package com.yangit.temp.common.util.md5;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class SignUtils {
	
	public static String source(Map<String, String> map ,String signkey) {
		StringBuilder sBuilder = new StringBuilder();
		Collection<String> keyset = map.keySet();
		List<String> list = new ArrayList<String>(keyset);
		Collections.sort(list);
		for (int i = 0; i < list.size(); i++) {
			String key = list.get(i);
			String value = map.get(list.get(i));
			sBuilder.append(key+"="+value+"&");
		}
		sBuilder.append(signkey);
		return sBuilder.toString();
	}
	
	public static String sign(Map<String, String> map ,String signkey) {
		StringBuilder sBuilder = new StringBuilder();
		Map<String, Object> treeMap = new TreeMap<String, Object>();
		treeMap.putAll(map);
		for (Map.Entry<String, Object> entry : treeMap.entrySet()) {
			String key = entry.getKey();
			Object value = entry.getValue();
			sBuilder.append(key+"="+value+"&");
		}
		sBuilder.append(signkey);
		return sBuilder.toString();		
	}
}